﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DAL_Document
/// </summary>
public class DAL_Document :clsConnection
{
    DataTable dt = new DataTable();
    clsQueryList clsquery = new clsQueryList();
    public DataTable DAL_Document_getDataByTeacherid(string tid)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM Document WHERE Status = 1 AND teacherid='" + tid + "' ORDER BY id desc");
        }
        catch
        {
        }
        return dt;
    }
    public DataTable DAL_Document_getDataById(int id)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM Document WHERE id=" + id);
        }
        catch
        {
        }
        return dt;
    }
    public DataTable DAL_Document_getMaxId()
    {
        try
        {
            dt = ExcuteQuery("SELECT MAX(id) as id FROM Document");
        }
        catch
        {
        }
        return dt;
    }
    public Boolean DAL_Document_Insert(DTO_Document obj)
    {
        try
        {
            string sql = "INSERT INTO Document(teacherid, title_textbooks, href_textbooks, status) VALUES(@teacherid, @title_textbooks, @href_textbooks ,@status)";
            AddParameter(new SqlParameter("@teacherid", obj.Teacherid));
            AddParameter(new SqlParameter("@title_textbooks", obj.Title_textbooks));
            AddParameter(new SqlParameter("@href_textbooks", obj.Href_textbooks));
            AddParameter(new SqlParameter("@status", obj.Status));

            if (ExcuteNonQuery(sql))
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        catch
        {
            return false;
        }
    }
    public Boolean DAL_Document_Update(DTO_Document obj)
    {
        try
        {
            string sql = "UPDATE Document SET title_textbooks = @title_textbooks, href_textbooks = @href_textbooks, status = @status WHERE id = @id";
            //AddParameter(new SqlParameter("@name", obj.Name));
            AddParameter(new SqlParameter("@title_textbooks", obj.Title_textbooks));
            AddParameter(new SqlParameter("@href_textbooks", obj.Href_textbooks));
            AddParameter(new SqlParameter("@status", obj.Status));
            AddParameter(new SqlParameter("@id", obj.ID));

            if (ExcuteNonQuery(sql))
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        catch
        {
            return false;
        }
    }
    public Boolean DAL_Document_addtodel(int id)
    {
        try
        {
            string sql = "delete from Document where id=" + id;
            clsquery.addSQL(sql);
        }
        catch
        {
            return false;
        }
        return true;
    }
    public Boolean DAL_Document_del()
    {
        try
        {
            clsquery.Execute();
        }
        catch
        {
            return false;
        }
        return true;
    }
}